home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / fmxutils.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  3.4 KB  |  117 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl.h>
  7. #pragma hdrstop
  8.  
  9. #include <shellapi.h>
  10. #include <stdio.h>
  11. #include "FmxUtils.h"
  12. //---------------------------------------------------------------------------
  13. TDateTime __fastcall FileDateTime(const AnsiString FileName)
  14. {
  15.   return (FileDateToDateTime(FileAge(FileName)));
  16. }
  17.  
  18. // GetFileSize function
  19. //
  20. //  Returns the size of the named file without opening the file.  If the file
  21. //  doesn't exist, returns -1.
  22. //
  23. long __fastcall GetFileSize(const AnsiString FileName)
  24. {
  25.   TSearchRec SearchRec;
  26.     if(FindFirst(ExpandFileName(FileName), faAnyFile, SearchRec)==0)
  27.       return SearchRec.Size;
  28.     else
  29.       return -1;
  30. }
  31.  
  32. // MoveFile procedure
  33. //
  34. //  Moves the file passed in FileName to the directory specified in DestDir.
  35. //  Tries to just rename the file.  If that fails, try to copy the file and
  36. //  delete the original.
  37. //
  38. //  Throws an exception if the source file is read-only, and therefore cannot
  39. //  be deleted/moved.
  40. //
  41. void __fastcall MoveFile(const AnsiString FileName,const AnsiString DestName)
  42. {
  43.   AnsiString Destination;
  44.   char FName[255];
  45.   bool ckmove;
  46.  
  47.   Destination=ExpandFileName(DestName);
  48.   GetFileTitle(FileName.c_str(),FName,255);
  49.  
  50.   if(HasAttr(FileName, faReadOnly)) {
  51.       char buffer[255];
  52.       sprintf(buffer,
  53.               "Error: Can not move the file '%s'.",
  54.               FileName.c_str());
  55.  
  56.       throw EFCantMove(buffer);
  57.   }
  58.  
  59.   if (HasAttr(Destination,faDirectory))
  60.       Destination=Destination+AnsiString(FName);
  61.  
  62.   ckmove= MoveFile(FileName.c_str(), Destination.c_str());
  63.  
  64.   if(!ckmove)
  65.     ShowMessage("Please give the destination filename");
  66. }
  67.  
  68. void __fastcall CopyFile(AnsiString FileName,AnsiString DestName)
  69. {
  70.   bool   ckcopy;
  71.   AnsiString Destination;
  72.   char   FName[255];
  73.  
  74.   GetFileTitle(FileName.c_str(),FName,255);
  75.   Destination = ExpandFileName(DestName);
  76.  
  77.   if(HasAttr(Destination,faDirectory))
  78.     Destination=Destination+FName;
  79.  
  80.   ckcopy= CopyFile(FileName.c_str(),Destination.c_str(),false);
  81.  
  82.   if(!ckcopy)
  83.     ShowMessage("Please give the destination filename");
  84.  
  85. }
  86. //---------------------------------------------------------------------------
  87. bool __fastcall HasAttr(const AnsiString FileName,const unsigned short Attr)
  88. {
  89.   int attribtest;
  90.  
  91.   attribtest=FileGetAttr(FileName);
  92.  
  93.   if(attribtest & Attr)
  94.     return true;
  95.   else
  96.     return false;
  97. }
  98.  
  99. //---------------------------------------------------------------------------
  100. int __fastcall ExecuteFile(const AnsiString FileName,
  101.                            const AnsiString Params,
  102.                            const AnsiString DefaultDir,
  103.                            int ShowCmd)
  104. {
  105.  
  106.   char zFileName[79], zParams[79], zDir[79];
  107.   return (int) ShellExecute(Application->MainForm->Handle,
  108.                             NULL,
  109.                             strcpy(zFileName,
  110.                                    FileName.c_str()),
  111.                             strcpy(zParams,
  112.                                    Params.c_str()),
  113.                             strcpy(zDir,
  114.                                    DefaultDir.c_str()),
  115.                             ShowCmd);
  116. }
  117.